import '../cartoon_media_info.dart';
import '../video_model.dart';
import 'module_detail_model.dart';

class HomeVideoLibrary {
  HomeVideoLibrary({
    this.canvas,
    this.orderBy,
    this.paymentType,
    this.vidTags,
    this.acgTags,
    this.timeType,
  });

  HomeVideoLibrary.fromJson(dynamic json) {
    if (json['canvas'] != null) {
      canvas = [];
      json['canvas'].forEach((v) {
        canvas?.add(TimeType.fromJson(v));
      });
    }
    if (json['orderBy'] != null) {
      orderBy = [];
      json['orderBy'].forEach((v) {
        orderBy?.add(TimeType.fromJson(v));
      });
    }
    if (json['paymentType'] != null) {
      paymentType = [];
      json['paymentType'].forEach((v) {
        paymentType?.add(TimeType.fromJson(v));
      });
    }
    if (json['vidTags'] != null) {
      vidTags = [];
      json['vidTags'].forEach((v) {
        vidTags?.add(Tags.fromJson(v));
      });
    }
    if (json['acgTags'] != null) {
      acgTags = [];
      json['acgTags'].forEach((v) {
        acgTags?.add(Tags.fromJson(v));
      });
    }
    if (json['timeType'] != null) {
      timeType = [];
      json['timeType'].forEach((v) {
        timeType?.add(TimeType.fromJson(v));
      });
    }
  }

  List<TimeType>? canvas;
  List<TimeType>? orderBy;
  List<TimeType>? paymentType;
  List<Tags>? vidTags;
  List<Tags>? acgTags;
  List<TimeType>? timeType;

  bool get isNotEmpty {
    return canvas?.isNotEmpty == true ||
        orderBy?.isNotEmpty == true ||
        paymentType?.isNotEmpty == true ||
        acgTags?.isNotEmpty == true ||
        vidTags?.isNotEmpty == true;
  }
}

class TimeType {
  TimeType({
    this.key,
    this.name,
  });

  bool get isACG => name?.contains("动漫") == true || name?.contains("漫画") == true;

  TimeType.fromJson(dynamic json) {
    key = json['key'];
    name = json['name'];
  }

  String? key;
  String? name;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['key'] = key;
    map['name'] = name;
    return map;
  }
}

class Keyword {
  Keyword({
    this.canvas,
    this.orderBy,
    this.tags,
    this.paymentType,
    this.timeType,
  });

  Keyword.fromJson(dynamic json) {
    canvas = json['canvas'] != null ? TimeType.fromJson(json['canvas']) : null;
    orderBy = json['orderBy'] != null ? TimeType.fromJson(json['orderBy']) : null;
    tags = json['tags'] != null ? Tags.fromJson(json['tags']) : null;
    paymentType = json['paymentType'] != null ? TimeType.fromJson(json['paymentType']) : null;
    timeType = json['timeType'] != null ? TimeType.fromJson(json['timeType']) : null;
  }

  TimeType? canvas;
  TimeType? orderBy;
  Tags? tags;
  TimeType? paymentType;
  TimeType? timeType;

  String get modelKey {
    return "${canvas?.name}${orderBy?.name}${tags?.name}${paymentType?.name}${timeType?.name}";
  }

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    if (canvas != null) {
      map['canvas'] = canvas?.toJson();
    }
    if (orderBy != null) {
      map['orderBy'] = orderBy?.toJson();
    }
    if (tags != null) {
      map['tags'] = tags?.toJson();
    }
    if (paymentType != null) {
      map['paymentType'] = paymentType?.toJson();
    }
    if (timeType != null) {
      map['timeType'] = timeType?.toJson();
    }
    return map;
  }
}

class HomeVideoLibraryResult {
  HomeVideoLibraryResult({
    this.hasNext,
    this.list,
    this.total,
  });

  HomeVideoLibraryResult.fromJson(dynamic json) {
    hasNext = json['hasNext'];
    info = json['section'] != null ? OfficialInfo.fromJson(json['section']) : null;
    if (json['list'] != null) {
      list = [];
      json['list'].forEach((v) {
        list?.add(VideoModel.fromJson(v));
      });
    }
    if (json['allMediaList'] != null) {
      allMediaList = [];
      json['allMediaList'].forEach((v) {
        allMediaList?.add(CartoonMediaInfo.fromJson(v));
      });
    }
    total = json['total'];
  }
  bool? hasNext;
  List<VideoModel>? list;
  List<CartoonMediaInfo>? allMediaList;
  int? total;
  OfficialInfo? info;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['hasNext'] = hasNext;
    if (list != null) {
      map['list'] = list?.map((v) => v.toJson()).toList();
    }
    map['total'] = total;
    return map;
  }
}

class OfficialInfo {
  OfficialInfo({
    this.commentCount,
    this.count,
    this.cover,
    this.id,
    this.likeCount,
    this.mediaStatus,
    this.name,
    this.portrait,
    this.type,
    this.userId,
    this.userName,
  });

  OfficialInfo.fromJson(dynamic json) {
    commentCount = json['commentCount'];
    count = json['count'];
    cover = json['cover'];
    id = json['id'];
    likeCount = json['likeCount'];
    mediaStatus = json['mediaStatus'] != null ? VidStatus.fromMap(json['mediaStatus']) : null;
    name = json['name'];
    portrait = json['portrait'];
    type = json['type'];
    userId = json['userId'];
    userName = json['userName'];
  }
  int? commentCount;
  int? count;
  String? cover;
  String? id;
  int? likeCount;
  VidStatus? mediaStatus;
  String? name;
  String? portrait;
  int? type;
  int? userId;
  String? userName;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['commentCount'] = commentCount;
    map['count'] = count;
    map['cover'] = cover;
    map['id'] = id;
    map['likeCount'] = likeCount;
    if (mediaStatus != null) {
      map['mediaStatus'] = mediaStatus?.toJson();
    }
    map['name'] = name;
    map['portrait'] = portrait;
    map['type'] = type;
    map['userId'] = userId;
    map['userName'] = userName;
    return map;
  }
}
